package com.jxc.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import com.jxc.dao.PermissionDAO;

/**
 * @包名   com.jxc.imp
 * @文件名 PermissionImpl.java
 * @作者   mopzyqing
 * @创建日期 Jul 21, 2010
 * @版本 V 1.0
 */
@Transactional
public class PermissionImpl implements PermissionDAO{

	@Resource private SessionFactory sessionFactory;

	//根据菜单ID获取权
	public List getPermissionByMuneId(int muneId){
		
		String queryString="from TbPermission where tbMenu.menuId="+muneId;
		Query queryObject = sessionFactory.getCurrentSession().createQuery(
				queryString);
		return queryObject.list();
	}
	//根据权限，删除已经授权出去的用户权限
	public void deleteTbPermissionRoleByPid(int op_id){
		String sql="delete from tb_permission_role where op_id="+op_id;
		sessionFactory.getCurrentSession().createSQLQuery(sql).executeUpdate();		
	}
	//删除权限
	public void deletePermissionById(int op_id) {
		deleteTbPermissionRoleByPid(op_id);
		String sql="delete from tb_permission where op_id="+op_id;
		sessionFactory.getCurrentSession().createSQLQuery(sql).executeUpdate();
	}
}
